#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void insertsort(int* arr, int len);
void print_f(int* arr, int len);
int main() {
	int arr[] = { 3,6,4,8,5,2,1 };
	int len = sizeof(arr) / sizeof(arr[0]);
	insertsort(arr, len);
	print_f(arr, len);
	return 0;
}

void insertsort(int* arr, int len) {
	int i,j;
	for (i = 0; i < len; i++) {
		int key = arr[i];
		j = i - 1;
		while (j >= 0 && arr[j]>key) {
			arr[j+1] = arr[j];            
			j--;
		}
		arr[j+1] = key;
	}

}

void print_f(int *arr,int len) {
	int i = 0;
	for (i = 0; i < len; i++) {
		printf("%d ", arr[i]);
	}
}
